package dongnv.poweramp.screen;

import android.content.Context;
import android.content.Intent;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import dongnv.poweramp.R;
import dongnv.poweramp.activity.HomeActivity;
import dongnv.poweramp.activity.ListFolderActivity;
import dongnv.poweramp.activity.ListSongPlayActivity;
import dongnv.poweramp.data.SongItem;

public class HomeScreen {
	public HomeScreen(Context context) {
		this.context = context;
		view = View.inflate(this.context, R.layout.home, null);
		playSong = (ImageView) view.findViewById(R.id.playSong);
		nextSong = (ImageView) view.findViewById(R.id.nextSong);
		backSong = (ImageView) view.findViewById(R.id.backSong);
		folder = (ImageView) view.findViewById(R.id.forderMusic);
		nameSong = (TextView) view.findViewById(R.id.nameSong);
		playContainer = (RelativeLayout) view.findViewById(R.id.playContainer);
		
		nameSong.setText(HomeActivity.systemManager.getCurrentSongItem().getName());
		if (HomeActivity.systemManager.isPlay()) {
			playSong.setImageResource(R.drawable.play_button);
		} else {
			playSong.setImageResource(R.drawable.pause_button);
		}
		
		playSong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (HomeActivity.systemManager.isPlay()) {
					playSong.setImageResource(R.drawable.pause_button);
					HomeActivity.systemManager.setPlay(false);
					HomeActivity.systemManager.getMediaPlayer().pause();
				} else {
					playSong.setImageResource(R.drawable.play_button);
					HomeActivity.systemManager.setPlay(true);
					HomeActivity.systemManager.getMediaPlayer().start();
				}
			}
		});

		playContainer.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(HomeScreen.this.context, ListSongPlayActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				HomeScreen.this.context.startActivity(intent);
			}
		});

		nextSong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});

		backSong.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});

		folder.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(HomeScreen.this.context, ListFolderActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				HomeScreen.this.context.startActivity(intent);
			}
		});

	}

	public void setPlay() {

	}

	public void setPause() {

	}

	public void setStop() {

	}

	public void updateSong() {
		SongItem songItem = HomeActivity.systemManager.getCurrentSongItem();
		nameSong.setText(songItem.getName());
		if (HomeActivity.systemManager.isPlay()) {
			playSong.setImageResource(R.drawable.play_button);
		} else {
			playSong.setImageResource(R.drawable.pause_button);
		}
	}

	public View getView() {
		return view;
	}

	private View view;
	private Context context;
	private ImageView playSong, nextSong, backSong, folder;
	private RelativeLayout playContainer;
	private TextView nameSong;
}
